package com.wx_zgwl_client;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 刘强
 *
 * @author判断数据是否连接的上
 * @create 2018-01-14 18:13
 **/
@RestController
public class HealthController {
    //标识当前数据库是否可以访问
    static boolean canVisitDb=true;

   /* @Autowired
    private Environment env;*/

    @GetMapping("/")
    public void qiang(){
        //System.out.println("-------------"+env.getProperty("liu.qiang"));
       System.out.println(sendPost("http://127.0.0.1:8200/refresh",""));

    }
    public  String sendPost(String url, String data) {
          String response = null;

            try {
                    CloseableHttpClient httpclient = null;
                    CloseableHttpResponse httpresponse = null;
                    try {
                            httpclient = HttpClients.createDefault();
                          HttpPost httppost = new HttpPost(url);
                           StringEntity stringentity = new StringEntity(data, ContentType.create("text/json", "UTF-8"));
                            httppost.setEntity(stringentity);
                            httpresponse = httpclient.execute(httppost);
                           response = EntityUtils
                                    .toString(httpresponse.getEntity());
                     } finally {
                           if (httpclient != null) {
                                   httpclient.close();
                                }
                         if (httpresponse != null) {
                                   httpresponse.close();
                             }
                        }
               } catch (Exception e) {
                   e.printStackTrace();
                }
           return response;
         }


}
